package org.zjx.analysis.analyze.window.impl;

import org.zjx.analysis.analyze.window.AbstractWindowAnalyzer;
import org.zjx.command.entity.Rect;
import org.zjx.command.util.ImageUtil;
import org.zjx.window.window.IWindow;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class GiveNpcAnalyzer extends AbstractWindowAnalyzer {

    public GiveNpcAnalyzer(IWindow window) {
        super("Npc 给与", "给与", window);
    }

    @Override
    protected void initResources() {
        areaMap.put("确认按钮", new ResolutionArea(ImageUtil.createRect(77,241,145,258)));
        areaMap.put("道具区域",new  ResolutionArea(ImageUtil.createRect(220,28,475,232)));

        imageMap.put("道具按钮-选中", new ResolutionImage(ImageUtil.createRect(333,241,392,258),
                ImageUtil.createImage("iVBORw0KGgoAAAANSUhEUgAAADwAAAASCAYAAAAHWr00AAACzUlEQVR42mMQ5mT/L8rOOiIwyK8MLWqm/3u0TEYEBvmVwZhZ7v9Iwgy2rMr/RxJmsAcSIwkzOLIp/6cEewrqYoit6p/z35lTDc6vC8v8Xx+RTdCsGC0nuFpsGCSXoO9OkXsZnNmV/1OCQWDvik1wvgefJlhs08ylYH6wjCmYv6h1Ml5zXLnU/hMLQuUtyHYvgyvIMgpwtX8y2BH+IvpEOXZ513Ss5gSIGYDlJ+fX/6/0TcSKG4AxDAKZ5n5ku5fBgwMYK1TCfgJa/+PU7P4XO4eDMQisBHoQxM6x9P8fLmuKU2+wuAHRMZxt4Ue2Gxm8OZX/k4vLgB75/O7D/zdPX/yvcIv6HyiohdehO+evxGlWmATEwys7p/6fml+HFc8oagSrybP0I9vNDL5cKv/JxbEK5v+XNk8AO+LSwRP/UzQdwOwsIw8wGxnfv3zj/90LV3GaFSFpCA+Yv3/+YMd//4Ll8638yHYzQwC3yn9K8bVjZ8A4TcsBbwzfu3gVpxlRUhAPL2no/T8xtRQrnpxRAVZTBPQwuW5lCOZR+U8pvg70LAhnakM8jE3N+d2HwB7GZUastCHRebjE2o9stzKE8ar+pxTfOH4GjLN1HPE69P7Fa1j1xwM92xWeAVYzPavif5NPHFbcGpAIVjO3qOF/gowRWW5liORT/U8phnk4Txfi4WhBDQw1Vw4c+/8A6GFs+jdPmP2fVLBr1hKy3MoQw6/2n1L8+OrN/x9evv6fLIW/ajmxfhtBs1p9Yv9/ff/xf5qcMVwsV9P2/6v7j/9PTyul2K0M8QLq/ynB9fZBcA+d3rjjfzsw6U2IzMTAnf4J/xOAMY/LnCoL7/93z1yElPh7DqHIJQpr/T+/fR/cHpB55LqXIUVY8z+5eEF+DdgBB+av+N/oEPT/28dPBJPi6Q3bMcxZWtYEl5+ZUoTTviINm/8PgFUbCID0kONmAK/0/E8iBv9iAAAAAElFTkSuQmCC")
        ));

        imageMap.put("任务按钮-选中", new ResolutionImage(ImageUtil.createRect(414,241,469,258),
                ImageUtil.createImage("iVBORw0KGgoAAAANSUhEUgAAADgAAAASCAYAAAAOsR1OAAADCElEQVR42t2UbUhTURzGD0Rp+Z4kFVTY1Klkkg6n+BJpjuky382lab6k5sswRS1CK0iUtQwTzUyCwsKiMuyNMgJJ+iBKkpaWJaH5KRPDklTw6d4zdtEN5+79uD/8LttzznnO8989Z2SLxXqYM0TjKYE5Q3zX7YQ5Q4LXi2DOkP3Mw5whBzaIIIRcaTTUJyqMzolw8ILMxmNNr4RdAWirbYLQLMYgYRYiCGHoXT/Ghj6jo/EWRgc+YuLLGGZ+/oJ+9XW9NeojsxJjcWEBxupObSOE5iThzEMIbLWeVePe5RYM9w7QRrofPKP605a70ORUoPSgEjJLl1U9lLsDsTA/zzXSXFaNq6oqjsfMj8dW/+seCM1J5JYi8EUVGEM3Ttjms0JXWIupnusjX9MjzS2EayzDMxRLS0u02cTtvnS8XJZCx+Zm/yDK1gNCcrIQxUYmGE9G+wfp5vr6YRttg/m+8jU9Dm1yQU1KIfc9wckbv6em6fpvzJFna3x4lHoKyaiDRDEb8aGACa8r/bEYW3eqF0gieHlmuAbhRtlF/GDu8fKanZ7Bw7oWFAdGg29OHSTGignGg++DI1yAR3XXYUq9vNlu4JPnFWow79/fOUyMfMWxHRLUJJ9kTsqHFePq1CLwzUvirV3Ahyr5UTTklNENE+3EKPQOQ9G+cEqxRPt2a5JyOY0lyd7dwCdHHIRPPb143nwb1fHZ3By2ykNiV8wtkSrQdu4SskQB4JuXJNm4gi/VsZk0iL6udPCgeqlfpEk+nfWtMLVaVJUQkpUobZlgPKmJ0zaor6du1jZYJo00yef41r04ExzNwb5RtpZrLIvzCxh41Q0hWUmqnRv4oo7LokH09XRHT6qf9lfw9rwQfoSubWeOov7Y1Pgk+p50QUhWkm4vBl80zJ1hS/e5IU1Faco8pQ1Zqea0K8l5yGAaX82rMjgG71+8oesmmT8YVsty2oN8Zyk3h61OzTUIyUqyHT3Al7p47RsscvYz6f6cZ46ZvodK5L9iTkd1PTd2v0pt4FHiHgQhWf8DiQY6iW4fcdIAAAAASUVORK5CYII=")
        ));
    }

    //选中道具栏
    public boolean chooseInventory(){
        ResolutionImage resolutionImage = imageMap.get("道具按钮-选中");
        BufferedImage bufferedImage = ImageUtil.cutImage(screenshot,conversion(windowArea,resolutionImage.getRectangle()));
//        List<Point> points = ImageUtil.matchTemplate(bufferedImage,resolutionImage.getPattern());
//        return !points.isEmpty();
        return ImageUtil.haveColor(bufferedImage, Collections.singletonList(new Color(72, 8, 35)));
    }

    //选中任务栏
    public boolean chooseTask(){
        ResolutionImage resolutionImage = imageMap.get("任务按钮-选中");
        BufferedImage bufferedImage = ImageUtil.cutImage(screenshot,conversion(windowArea,resolutionImage.getRectangle()));
//        List<Point> points = ImageUtil.matchTemplate(bufferedImage,resolutionImage.getPattern());
//        return !points.isEmpty();
        return ImageUtil.haveColor(bufferedImage, Collections.singletonList(new Color(72, 8, 35)));
    }

    public Rectangle getInventoryButtonRectangle(){
        ResolutionImage resolutionImage = imageMap.get("道具按钮-选中");
        return conversion(windowArea,resolutionImage.getRectangle());
    }

    public Rectangle getTaskButtonRectangle(){
        ResolutionImage resolutionImage = imageMap.get("任务按钮-选中");
        return conversion(windowArea,resolutionImage.getRectangle());
    }

    public Rectangle getSureButtonRectangle(){
        return conversion(windowArea,areaMap.get("确认按钮").getRectangle());
    }

    public Rectangle getItemIndexRectangle(int index){
        Rectangle itemsArea = conversion(windowArea,areaMap.get("道具区域").getRectangle());
         PropAnalysis propAnalysis = new PropAnalysis(ImageUtil.cutImage(screenshot,itemsArea));
         return conversion(itemsArea,propAnalysis.getIndexArea(index));
    }

    @Override
    public Rectangle closeArea() {
        return ImageUtil.createRect(473,7,482,16);
    }

    @Override
    public Rectangle getOriginBounds() {
        return ImageUtil.createRect(154,162,645,432);
    }

    @Override
    public Rectangle getRefImageArea() {
        return ImageUtil.createRect(173,3,294,15);
    }

    @Override
    public BufferedImage getRefImage() {
        return  ImageUtil.createImage("iVBORw0KGgoAAAANSUhEUgAAAHkAAAANCAYAAACNScGeAAAIPElEQVR42rVYCVcUxxb2f70YIXpeonnKvmp4Ig7KYmRRBBVEMAZDWERAGBhBNplhl0WGfXOAABIQJ7KDCOKCCrhgEt99fW9P1XTTPQrJyT3nO1TdulX1VX23qmvY8S+HDJDCye8m6G+PUHmnU7Y6nHO2jF2ufw97v8sH/zNVqm3xqe025z0SXglB52qtOFsjrwvwE2I+xXuPpw6u6kx/ew2bweb40iUHPAJKwTvYYBtBpeAZqKdYGUcVXTZrybBDWvnCMQOYsY67nLNUy/+EoGqovPMAPnz4U+FvuztNPJu7phQbuNvjBmzVdKVDNudOzumhmM9xjEowbnm+odFF3m9m/uWW+y0ur9HaiqtGYEPYj40Pf2wZO+JTmqCtZxI6TFOw/maDBjRPLENn75QFM4QO0zT8lNFBAtu5aMHZr4BEZ4TtXcWyd7BetgF2brmfhbOmGMLiGuBQcKmiDa2keoTX7d1zoaN3lvw/pLXT35oms4IHQeCXXdgH+4TbQJqooRdq+ebtPZTL4w8cKYTWnmno7JslMGN1hnbTDK2TcapufEBxnnjqLJh//AqWn6/LfNhPmjR/fvwfGGrvy3ibJ5/B6G9PZAcq3zAk9h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ZV9Cv2+93737f+b9SROfg/HFbFHOK7F5wAAAAASUVORK5CYII=");
    }

    @Override
    public void analyze(BufferedImage image) {

    }
}
